﻿//********************************************************************************//
//创建日期：<创建日期，2017-01-11>
//创建作者：<孙雪婷，sunxueting@shanghai3h.com>
//功能说明：地下水、地表水用户信息
//********************************************************************************//
using BLL;
using BLL.Access;
using DevExpress.Web;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;

namespace Web.Pages.QuShui.XiTongJK
{
    public partial class YongHuXX_DXS : BasePage
    {
        #region 属性

        /// <summary>
        /// 保存结果集1
        /// </summary>
        private DataTable dtYongHuXX
        {
            get
            {
                return ViewState["dtYongHuXX"] as DataTable;
            }
            set
            {
                ViewState["dtYongHuXX"] = value;
            }
        }

       


        #endregion

        #region 变量

        /// <summary>
        /// 存储过程调用类
        /// </summary>
        SpHelper _SpHelper = new SpHelper();

        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            {
                InitData();
            }
            this.ScriptManager1.RegisterPostBackControl(this.btnExport);  
            LoadGridData();
        }



        /// <summary>
        /// tab1导出excel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExportExcel_Click(object sender, EventArgs e)
        {
            if (this.dtYongHuXX != null)
            {
                //获取选中的数据
                DataTable dt = PageTools.GetCheckedData(this.gvYHXX, this.dtYongHuXX, "cid", "id");
                //筛选及重命名需要的列
                dt.Columns.Remove("ID");
                dt.Columns.Remove("ROWNUM");
                dt.Columns[0].ColumnName = "用户号";
                dt.Columns[1].ColumnName = "用户名";
                dt.Columns[2].ColumnName = "水价";
                dt.Columns[3].ColumnName = "行政区";
                dt.Columns[4].ColumnName = "环线标记";
                dt.Columns[5].ColumnName = "取水用途";
                dt.Columns[6].ColumnName = "流域";
                dt.Columns[7].ColumnName = "水资源分区";
                dt.Columns[8].ColumnName = "装裱计量";
                dt.Columns[9].ColumnName = "联系人";
                dt.Columns[10].ColumnName = "联系部门";
                dt.Columns[11].ColumnName = "邮编";
                dt.Columns[12].ColumnName = "联系电话";
                dt.Columns[13].ColumnName = "地址";
                PageTools.CreateExcel(dt, string.Format("{0}用户信息.xls", this.txtShuiLiangYM.Text));
            }
        }



        protected void gvYHXX_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
        {
            LoadGridData();
        }

        #endregion

        #region 方法

        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData()
        {
           
           // gvYHXX.SettingsPager.Mode = GridViewPagerMode.EndlessPaging;
            //水量年月
            int i_ym = BusinessTool.GetSLYMorZWNY(1, 2);
            txtShuiLiangYM.Text = i_ym.ToString();
            LoadGridData();
        }


        /// <summary>
        /// 加载查询数据
        /// </summary>
        private void LoadGridData()
        {
            int WTYEP = Convert.ToInt32(this.Request.QueryString["wtype"]);
            int ym = Convert.ToInt32(txtShuiLiangYM.Text);
            this.dtYongHuXX = _SpHelper.P_QSCX_YHXX(ym, WTYEP).Tables[0];
            if (this.dtYongHuXX != null && this.dtYongHuXX.Rows.Count > 0)
            {
                zjl.Text = "共" + this.dtYongHuXX.Rows.Count.ToString() + "条";
            }

            Dictionary<string, string> list = PageTools.GetCheckedValueList(this.gvYHXX, "cid", "id");
            this.gvYHXX.DataSource = this.dtYongHuXX;
            this.gvYHXX.DataBind();
            //绑定后，给每一行的checkbox的clientname赋值
            for (int i = 0; i < gvYHXX.VisibleRowCount; i++)
            {
                ASPxCheckBox cb = (ASPxCheckBox)gvYHXX.FindRowCellTemplateControl(i, (GridViewDataColumn)gvYHXX.Columns[0], "cid");
                cb.ClientInstanceName = "checked" + i;
            }
            //绑定后默认全选
            PageTools.SetCheckedAll(this.gvYHXX, "cid", true);
            //重新选中项
            PageTools.SetCheckedValueList(this.gvYHXX, "cid", "id", list);

        }
       
        #endregion

        protected void cbAll_CheckedChanged(object sender, EventArgs e)
        {
            ASPxCheckBox cbHead = (ASPxCheckBox)sender;
            int count = this.gvYHXX.VisibleRowCount;
            if (cbHead.Checked == true)
            {
                for (int i = 0; i < count; i++)
                {
                    ASPxCheckBox cks = this.gvYHXX.FindRowCellTemplateControl(i, null, "Ch") as ASPxCheckBox;
                    cks.Checked = true;
                }
            }
            else
            {
                for (int i = 0; i < count; i++)
                {
                    ASPxCheckBox cks = this.gvYHXX.FindRowCellTemplateControl(i, null, "Ch") as ASPxCheckBox;
                    cks.Checked = false;
                }
            }

        }

    }
}